package com.ymatou.iapi.quickturnover.testcase;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.quickturnover.parameter.WriteOffAdvanceOrderReqBean;
import com.ymatou.iapi.quickturnover.service.AdvanceOrderService;
import com.ymatou.iapi.quickturnover.service.WriteOffAdvanceOrderReqCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AccountCallServiceV2;
import com.ymttest.database.model.AdvanceApplyBill;
import com.ymttest.database.model.AdvanceOrder;
import com.ymttest.database.model.YmtAccountEntry;
import com.ymttest.database.model.YmtSettlementInvoice;
import com.ymttest.database.sqlwapper.AccountDefaultWapper;
import com.ymttest.database.sqlwapper.AdvanceOrderDefaultWapper;
import com.ymttest.database.sqlwapper.DefaultWapper;
import com.ymttest.database.sqlwapper.YmtSettlementInvoiceWapper;
/**
*订单凭证销账接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_WriteOffAdvanceOrderReq{
	private static WriteOffAdvanceOrderReqBean writeoffadvanceorderreqBean;
	private static WriteOffAdvanceOrderReqCall writeoffadvanceorderreqCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("订单凭证销账");
	}

	@Before
	public void caseUp() {
		writeoffadvanceorderreqBean=new WriteOffAdvanceOrderReqBean();
		writeoffadvanceorderreqCall=new WriteOffAdvanceOrderReqCall();
		AdvanceOrderService.applyAdvanceAllBill();

	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(writeoffadvanceorderreqCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
//对于状态为3已预支的销账结果校验
private void verifyDB(BigDecimal advanced_amount,int sellerId,String bill_id){	
		try {
			AdvanceOrderDefaultWapper advanceOrderDefaultWapper=new AdvanceOrderDefaultWapper();	
	        DefaultWapper defaultWapper = new DefaultWapper();	
			//advance_order
	        Map advance = new HashMap();  
	        long orderId=writeoffadvanceorderreqBean.getOrderId();
	        int businessType=	writeoffadvanceorderreqBean.getBusinessType();
	        String mark=null;
			/*	1 订单取消
			 * 100 确认收货
			 * 17 退款退货*/
	        if (businessType==100){
	        	mark="订单确认收货";
	        }
	        else if(businessType==1){	        	
	        	mark="订单取消";
	        }
	        else {
	        	mark="订单退货退款";
			}        
	        advance.put("order_id",orderId );
	        List<AdvanceOrder> advanceOrderList=advanceOrderDefaultWapper.selectAdvanceOrder(advance);
	        // 查询结算表
	        Map settMap=new HashMap(); 
	        settMap.put("orderId", orderId); 
	        settMap.put("businessType", 12); 
			List<YmtSettlementInvoice> ymtSettlementInvoiceList=new YmtSettlementInvoiceWapper().selectYmtSettlementInvoice(settMap);
			//资金流水表
			Map act = new HashMap();      
	        act.put("userId", sellerId);         
	        act.put("originalNo",String.valueOf(orderId));
	        List<YmtAccountEntry> ymtAccountEntryList= new AccountDefaultWapper().selectAccountEntryByBizNo(act);        
	        Logger.comment("校验advance_order表");	        
	        AdvanceOrder advanceOrder=advanceOrderList.get(0);

    		Logger.verifyEquals(5, advanceOrder.getAdvance_status(), "验证advance_status");
    		Logger.verifyEquals(advanced_amount, advanceOrder.getWrittenoff_amount(), "验证writtenoff_amount");
    		Logger.verifyEquals(mark+"，冲销预支", advanceOrder.getRemark(), "验证remark");
    		Logger.verifyEquals(sellerId, advanceOrder.getSeller_id(), "验证seller_id");
    		Logger.verifyEquals(bill_id, advanceOrder.getBill_id(), "验证bill_id");
   
	        Logger.comment("校验Ymt_SettlementInvoice表");
    		Logger.verifyEquals(1, ymtSettlementInvoiceList.size(), "验证结算Ymt_SettlementInvoice 查询记录为1");
    		
    		YmtSettlementInvoice ymtSettlementInvoice=ymtSettlementInvoiceList.get(0);
 				
    		Logger.verifyEquals(advanced_amount.setScale(2), ymtSettlementInvoice.getTotalAmount(), "验证结算TotalAmount");
    		Logger.verifyEquals(advanced_amount.setScale(2), ymtSettlementInvoice.getCashAmount(), "验证结算CashAmount");
    		Logger.verifyEquals(sellerId, ymtSettlementInvoice.getSellerId(), "验证结算商家sellerid");
    		Logger.verifyEquals("冲销预支-"+mark+"，预支申请编号"+bill_id, ymtSettlementInvoice.getRemark(), "验证结算remark");
    		Logger.verifyEquals(1, ymtSettlementInvoice.getSettlementStatus(), "验证结算SettlementStatus");
    		Logger.verifyEquals(2, ymtSettlementInvoice.getSettlementUser(), "验证结算SettlementUser");

	  
    	
	        Logger.comment("校验Ymt_AccountEntry表");
    		Logger.verifyEquals(1, ymtAccountEntryList.size(), "验证结算Ymt_AccountEntry 查询记录为1");
		    YmtAccountEntry  ymtAccountEntry=ymtAccountEntryList.get(0);
		    
    		Logger.verifyEquals(advanced_amount.divide(new BigDecimal(-1),2,4), ymtAccountEntry.getAmount(), "验证Amount");
    		Logger.verifyEquals(sellerId, ymtAccountEntry.getUserid(), "验证UserId");
    		Logger.verifyEquals(300033, ymtAccountEntry.getBizcode(), "验证UserId");
    		Logger.verifyEquals("冲销预支-"+mark+"，预支申请编号"+bill_id, ymtAccountEntry.getMemo(), "验证Memo");

		} catch (Exception e) {
			Logger.fail(e);
		}
		
	}
//对于状态为1,2 未预支的销账结果校验
private void verifyDB2(BigDecimal advanced_amount,int sellerId,String bill_id){	
	try {
		AdvanceOrderDefaultWapper advanceOrderDefaultWapper=new AdvanceOrderDefaultWapper();	
        DefaultWapper defaultWapper = new DefaultWapper();	
		//advance_order
        Map advance = new HashMap();  
        long orderId=writeoffadvanceorderreqBean.getOrderId();
    
        advance.put("order_id",orderId );
        List<AdvanceOrder> advanceOrderList=advanceOrderDefaultWapper.selectAdvanceOrder(advance);
        // 查询结算表
        Map settMap=new HashMap(); 
        settMap.put("orderId", orderId); 
        settMap.put("businessType", 12); 
		List<YmtSettlementInvoice> ymtSettlementInvoiceList=new YmtSettlementInvoiceWapper().selectYmtSettlementInvoice(settMap);
		//资金流水表
		Map act = new HashMap();      
        act.put("userId", sellerId);         
        act.put("originalNo",String.valueOf(orderId));
        List<YmtAccountEntry> ymtAccountEntryList= new AccountDefaultWapper().selectAccountEntryByBizNo(act);
        
        Logger.comment("校验advance_order表");
        advanceOrderList.forEach(advanceOrder->
	        		{
		        		Logger.verifyEquals(5, advanceOrder.getAdvance_status(), "验证advance_status");
		        		//Logger.verifyEquals(sellerId, advanceOrder.getSeller_id(), "验证seller_id");
		        		//Logger.verifyEquals(billId, advanceOrder.getBill_id(), "验证bill_id");
	        		}		

        		);	    
        Logger.comment("校验Ymt_SettlementInvoice表");
		Logger.verifyEquals(0, ymtSettlementInvoiceList.size(), "验证结算Ymt_SettlementInvoice 查询记录为0");

        Logger.comment("校验Ymt_AccountEntry表");
		Logger.verifyEquals(0, ymtAccountEntryList.size(), "验证结算Ymt_AccountEntry 查询记录为0");

	} catch (Exception e) {
		Logger.fail(e);
	}
	
}
	
//销账失败校验
private void verifyDB3(BigDecimal advanced_amount,int sellerId,String bill_id){	
		try {
			AdvanceOrderDefaultWapper advanceOrderDefaultWapper=new AdvanceOrderDefaultWapper();	
	        DefaultWapper defaultWapper = new DefaultWapper();	
			//advance_order
	        Map advance = new HashMap();  
	        long orderId=writeoffadvanceorderreqBean.getOrderId();
	        int businessType=	writeoffadvanceorderreqBean.getBusinessType();
	        String mark=null;
			/*	1 订单取消
			 * 100 确认收货
			 * 17 退款退货*/
	        if (businessType==100){
	        	mark="订单确认收货";
	        }
	        else if(businessType==1){	        	
	        	mark="订单取消";
	        }
	        else {
	        	mark="订单退货退款";
			}        
	        advance.put("order_id",orderId );
	        List<AdvanceOrder> advanceOrderList=advanceOrderDefaultWapper.selectAdvanceOrder(advance);
	        // 查询结算表
	        Map settMap=new HashMap(); 
	        settMap.put("orderId", orderId); 
	        settMap.put("businessType", 12); 
			List<YmtSettlementInvoice> ymtSettlementInvoiceList=new YmtSettlementInvoiceWapper().selectYmtSettlementInvoice(settMap);
			//资金流水表
			Map act = new HashMap();      
	        act.put("userId", sellerId);         
	        act.put("originalNo",String.valueOf(orderId));
	        List<YmtAccountEntry> ymtAccountEntryList= new AccountDefaultWapper().selectAccountEntryByBizNo(act);        
	        Logger.comment("校验advance_order表");	        
	        AdvanceOrder advanceOrder=advanceOrderList.get(0);

  		Logger.verifyEquals(4, advanceOrder.getAdvance_status(), "验证advance_status");
  		Logger.verifyEquals(BigDecimal.ZERO.setScale(2), advanceOrder.getWrittenoff_amount(), "验证writtenoff_amount");
  		Logger.verifyEquals(advanced_amount, advanceOrder.getWriteoff_fail_amount(), "验证writeoff_fail_amount");
  		Logger.verifyEquals(mark+"，冲销预支", advanceOrder.getRemark(), "验证remark");
  		Logger.verifyEquals(sellerId, advanceOrder.getSeller_id(), "验证seller_id");
  		Logger.verifyEquals(bill_id, advanceOrder.getBill_id(), "验证bill_id");
 
	        Logger.comment("校验Ymt_SettlementInvoice表");
  		Logger.verifyEquals(1, ymtSettlementInvoiceList.size(), "验证结算Ymt_SettlementInvoice 查询记录为1");
  		
  		YmtSettlementInvoice ymtSettlementInvoice=ymtSettlementInvoiceList.get(0);
				
  		Logger.verifyEquals(advanced_amount.setScale(2), ymtSettlementInvoice.getTotalAmount(), "验证结算TotalAmount");
  		Logger.verifyEquals(advanced_amount.setScale(2), ymtSettlementInvoice.getCashAmount(), "验证结算CashAmount");
  		Logger.verifyEquals(sellerId, ymtSettlementInvoice.getSellerId(), "验证结算商家sellerid");
  		Logger.verifyEquals("冲销预支-"+mark+"，预支申请编号"+bill_id, ymtSettlementInvoice.getRemark(), "验证结算remark");
  		Logger.verifyEquals(0, ymtSettlementInvoice.getSettlementStatus(), "验证结算SettlementStatus");
  		Logger.verifyEquals(2, ymtSettlementInvoice.getSettlementUser(), "验证结算SettlementUser");

	  
  	
	    Logger.comment("校验Ymt_AccountEntry表");
  		Logger.verifyEquals(0, ymtAccountEntryList.size(), "验证结算Ymt_AccountEntry 查询记录为0");
		  

		} catch (Exception e) {
			Logger.fail(e);
		}
		
	}
@Test
	@Category({P1.class})
	@TestCase
	public void Tc_WriteOffAdvanceOrderReq_001() {
		Logger.start(true,"订单 确认收货凭证销账");
		try {
            Logger.comment("准备前置数据");
			/*	1 订单取消
			 * 100 确认收货
			 * 17 退款退货*/
			int businessType=100;		
			Map map=AdvanceOrderService.createAdvanceOrderAndApply();			
	        Thread.sleep(2000);
			BigDecimal advanced_amount = (BigDecimal) map.get("advanced_amount");
	        int sellerId = (Integer) map.get("sellerId");
	       long orderId = (Long) map.get("orderId");
	        String bill_id=(String) map.get("billId");
	        
            Logger.comment("准备前置数据结束");
			writeoffadvanceorderreqBean.setBusinessType(businessType);
			writeoffadvanceorderreqBean.setOrderId(orderId);
			writeoffadvanceorderreqCall.setData(writeoffadvanceorderreqBean);
			writeoffadvanceorderreqCall.callService();			
			Logger.verifyEquals("ok", writeoffadvanceorderreqCall.getReturnData(), "验证接口返回ok");		
			Thread.sleep(2000);
			if (writeoffadvanceorderreqCall.getReturnData().equals("ok")){
				verifyDB(advanced_amount, sellerId,bill_id);				
			}
						
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_WriteOffAdvanceOrderReq_002() {
		Logger.start(true,"订单 订单取消凭证销账");
		try {
            Logger.comment("准备前置数据");
			/*	1 订单取消
			 * 100 确认收货
			 * 17 退款退货*/
			int businessType=1;		
			Map map=AdvanceOrderService.createAdvanceOrderAndApply();			
	        
			BigDecimal advanced_amount = (BigDecimal) map.get("advanced_amount");
	        int sellerId = (Integer) map.get("sellerId");
	       long orderId = (Long) map.get("orderId");
	        String bill_id=(String) map.get("billId");
            Logger.comment("准备前置数据结束");
			writeoffadvanceorderreqBean.setBusinessType(businessType);
			writeoffadvanceorderreqBean.setOrderId(orderId);
			writeoffadvanceorderreqCall.setData(writeoffadvanceorderreqBean);
			writeoffadvanceorderreqCall.callService();			
			Logger.verifyEquals("ok", writeoffadvanceorderreqCall.getReturnData(), "验证接口返回ok");		
			Thread.sleep(2000);
			if (writeoffadvanceorderreqCall.getReturnData().equals("ok")){
				verifyDB(advanced_amount, sellerId,bill_id);				
			}
						
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_WriteOffAdvanceOrderReq_003() {
		Logger.start(true,"对状态为5的重复销账");
		try {
            Logger.comment("准备前置数据");
			/*	1 订单取消
			 * 100 确认收货
			 * 17 退款退货*/
			int businessType=100;		
			Map map=AdvanceOrderService.createAdvanceOrderAndApply();			
	        Thread.sleep(2000);
			BigDecimal advanced_amount = (BigDecimal) map.get("advanced_amount");
	        int sellerId = (Integer) map.get("sellerId");
	       long orderId = (Long) map.get("orderId");
	        String bill_id=(String) map.get("billId");
	        
            Logger.comment("准备前置数据结束");
			writeoffadvanceorderreqBean.setBusinessType(businessType);
			writeoffadvanceorderreqBean.setOrderId(orderId);
			writeoffadvanceorderreqCall.setData(writeoffadvanceorderreqBean);
			writeoffadvanceorderreqCall.callService();			
			Logger.verifyEquals("ok", writeoffadvanceorderreqCall.getReturnData(), "验证接口返回ok");		
			Thread.sleep(2000);
			if (writeoffadvanceorderreqCall.getReturnData().equals("ok")){
				verifyDB(advanced_amount, sellerId,bill_id);				
			}
			Logger.comment("重复销账");
			writeoffadvanceorderreqCall.callService();			
			Thread.sleep(2000);
			if (writeoffadvanceorderreqCall.getReturnData().equals("ok")){
				verifyDB(advanced_amount, sellerId,bill_id);				
			}
						
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_WriteOffAdvanceOrderReq_004() {
		Logger.start(true,"订单 退款退货凭证销账");
		try {
            Logger.comment("准备前置数据");
			/*	1 订单取消
			 * 100 确认收货
			 * 17 退款退货*/
			int businessType=17;		
			Map map=AdvanceOrderService.createAdvanceOrderAndApply();			
	        
			BigDecimal advanced_amount = (BigDecimal) map.get("advanced_amount");
	        int sellerId = (Integer) map.get("sellerId");
	       long orderId = (Long) map.get("orderId");
	        String bill_id=(String) map.get("billId");

            Logger.comment("准备前置数据结束");
			writeoffadvanceorderreqBean.setBusinessType(businessType);
			writeoffadvanceorderreqBean.setOrderId(orderId);
			writeoffadvanceorderreqCall.setData(writeoffadvanceorderreqBean);
			writeoffadvanceorderreqCall.callService();			
			Logger.verifyEquals("ok", writeoffadvanceorderreqCall.getReturnData(), "验证接口返回ok");		
			Thread.sleep(2000);
			if (writeoffadvanceorderreqCall.getReturnData().equals("ok")){
				verifyDB(advanced_amount, sellerId,bill_id);				
			}
						
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_WriteOffAdvanceOrderReq_005() {
		Logger.start(false,"订单凭证advance_status 为1 销账");
		try {
            Logger.comment("准备前置数据");
			/*	1 订单取消
			 * 100 确认收货
			 * 17 退款退货*/
			int businessType=17;		
			Map map=AdvanceOrderService.createAdvanceOrder();			
			Thread.sleep(2000);
			BigDecimal advanced_amount = (BigDecimal) map.get("advanced_amount");
	        int sellerId = (Integer) map.get("sellerId");
	       long orderId = (Long) map.get("orderId");
	        String bill_id=(String) map.get("billId");

            Logger.comment("准备前置数据结束"); 
			writeoffadvanceorderreqBean.setBusinessType(businessType);
			writeoffadvanceorderreqBean.setOrderId(orderId);
			writeoffadvanceorderreqCall.setData(writeoffadvanceorderreqBean);
			writeoffadvanceorderreqCall.callService();			
			Logger.verifyEquals("ok", writeoffadvanceorderreqCall.getReturnData(), "验证接口返回ok");		
			Thread.sleep(2000);
			if (writeoffadvanceorderreqCall.getReturnData().equals("ok")){
				verifyDB2(BigDecimal.ZERO, sellerId,"");				
			}
						
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_WriteOffAdvanceOrderReq_006() {
		Logger.start(false,"订单凭证advance_status 为2销账");
		try {
            Logger.comment("准备前置数据");
			/*	1 订单取消
			 * 100 确认收货
			 * 17 退款退货*/
			int businessType=17;		
			Map map=AdvanceOrderService.createAdvanceOrderAndGrantcredit();			
	        
			BigDecimal advanced_amount = (BigDecimal) map.get("advanced_amount");
	        int sellerId = (Integer) map.get("sellerId");
	       long orderId = (Long) map.get("orderId");
	        String bill_id=(String) map.get("billId");

            Logger.comment("准备前置数据结束");
			writeoffadvanceorderreqBean.setBusinessType(businessType);
			writeoffadvanceorderreqBean.setOrderId(orderId);
			writeoffadvanceorderreqCall.setData(writeoffadvanceorderreqBean);
			writeoffadvanceorderreqCall.callService();			
			Logger.verifyEquals("ok", writeoffadvanceorderreqCall.getReturnData(), "验证接口返回ok");		
			Thread.sleep(2000);
			if (writeoffadvanceorderreqCall.getReturnData().equals("ok")){
				verifyDB2(BigDecimal.ZERO, sellerId,"");				
			}						
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_WriteOffAdvanceOrderReq_007() {
		Logger.start(false,"seller id 不存在");
		try {
            Logger.comment("准备前置数据");
			/*	1 订单取消
			 * 100 确认收货
			 * 17 退款退货*/
			int businessType=17;		
			Map map=AdvanceOrderService.createAdvanceOrder();			
			Thread.sleep(2000);
			BigDecimal advanced_amount = (BigDecimal) map.get("advanced_amount");
	        int sellerId = 11111111;
	       long orderId = (Long) map.get("orderId");

            Logger.comment("准备前置数据结束");
			writeoffadvanceorderreqBean.setBusinessType(businessType);
			writeoffadvanceorderreqBean.setOrderId(orderId);
			writeoffadvanceorderreqCall.setData(writeoffadvanceorderreqBean);
			writeoffadvanceorderreqCall.callService();			
			Logger.verifyEquals("ok", writeoffadvanceorderreqCall.getReturnData(), "验证接口返回ok");		
			Thread.sleep(2000);
			if (writeoffadvanceorderreqCall.getReturnData().equals("ok")){
				verifyDB2(BigDecimal.ZERO, sellerId,"");				
			}						
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_WriteOffAdvanceOrderReq_008() {
		Logger.start(false,"order id 不存在");
		try {
            Logger.comment("准备前置数据");
			/*	1 订单取消
			 * 100 确认收货
			 * 17 退款退货*/
			int businessType=17;		
			Map map=AdvanceOrderService.createAdvanceOrder();			
			Thread.sleep(2000);
			BigDecimal advanced_amount = (BigDecimal) map.get("advanced_amount");
	        int sellerId = (Integer) map.get("sellerId");
	        long orderId = 111111;

            Logger.comment("准备前置数据结束");
			writeoffadvanceorderreqBean.setBusinessType(businessType);
			writeoffadvanceorderreqBean.setOrderId(orderId);
			writeoffadvanceorderreqCall.setData(writeoffadvanceorderreqBean);
			writeoffadvanceorderreqCall.callService();			
			Logger.verifyEquals("ok", writeoffadvanceorderreqCall.getReturnData(), "验证接口返回ok");		
			Thread.sleep(2000);
			if (writeoffadvanceorderreqCall.getReturnData().equals("ok")){
				verifyDB2(BigDecimal.ZERO, sellerId,"");				
			}						
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_WriteOffAdvanceOrderReq_009() {
		Logger.start(false,"order id 为null");
		try {
            Logger.comment("准备前置数据");
			/*	1 订单取消
			 * 100 确认收货
			 * 17 退款退货*/
			int businessType=17;		
			Map map=AdvanceOrderService.createAdvanceOrder();			
			Thread.sleep(2000);
			BigDecimal advanced_amount = (BigDecimal) map.get("advanced_amount");
	        int sellerId = (Integer) map.get("sellerId");
	       long orderId = (Long) map.get("orderId");

            Logger.comment("准备前置数据结束");
			writeoffadvanceorderreqBean.setBusinessType(businessType);
			//writeoffadvanceorderreqBean.setOrderId(orderId);
			writeoffadvanceorderreqCall.setData(writeoffadvanceorderreqBean);
			writeoffadvanceorderreqCall.callService();			
			Logger.verifyEquals("fail", writeoffadvanceorderreqCall.getReturnData(), "验证接口返回ok");		
			Thread.sleep(2000);
			if (writeoffadvanceorderreqCall.getReturnData().equals("ok")){
				verifyDB2(BigDecimal.ZERO, sellerId,"");				
			}						
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_WriteOffAdvanceOrderReq_010() {
		Logger.start(false,"businessType 不存在l");
		try {
            Logger.comment("准备前置数据");
			/*	1 订单取消
			 * 100 确认收货
			 * 17 退款退货*/
			int businessType=18;		
			Map map=AdvanceOrderService.createAdvanceOrder();			
			Thread.sleep(2000);
			BigDecimal advanced_amount = (BigDecimal) map.get("advanced_amount");
	        int sellerId = (Integer) map.get("sellerId");
	       long orderId = (Long) map.get("orderId");

            Logger.comment("准备前置数据结束");
			writeoffadvanceorderreqBean.setBusinessType(businessType);
			writeoffadvanceorderreqBean.setOrderId(orderId);
			writeoffadvanceorderreqCall.setData(writeoffadvanceorderreqBean);
			writeoffadvanceorderreqCall.callService();			
			Logger.verifyEquals("ok", writeoffadvanceorderreqCall.getReturnData(), "验证接口返回ok");		
					
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_WriteOffAdvanceOrderReq_011() {
		Logger.start(false,"businessType 为nulll");
		try {
            Logger.comment("准备前置数据");
			/*	1 订单取消
			 * 100 确认收货
			 * 17 退款退货*/
			int businessType=18;		
			Map map=AdvanceOrderService.createAdvanceOrder();			
			Thread.sleep(2000);
			BigDecimal advanced_amount = (BigDecimal) map.get("advanced_amount");
	        int sellerId = (Integer) map.get("sellerId");
	       long orderId = (Long) map.get("orderId");

            Logger.comment("准备前置数据结束");
			//writeoffadvanceorderreqBean.setBusinessType(businessType);
			writeoffadvanceorderreqBean.setOrderId(orderId);
			writeoffadvanceorderreqCall.setData(writeoffadvanceorderreqBean);
			writeoffadvanceorderreqCall.callService();			
			Logger.verifyEquals("fail", writeoffadvanceorderreqCall.getReturnData(), "验证接口返回ok");		
					
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_WriteOffAdvanceOrderReq_012() {
		Logger.start(true,"商家账户余额不足，销账失败。校验补偿逻辑");
		try {
            Logger.comment("准备前置数据");
			/*	1 订单取消
			 * 100 确认收货
			 * 17 退款退货*/
			int businessType=100;		
			Map map=AdvanceOrderService.createAdvanceOrderAndApply();			
	        Thread.sleep(2000);
			BigDecimal advanced_amount = (BigDecimal) map.get("advanced_amount");
	        int sellerId = (Integer) map.get("sellerId");
	       long orderId = (Long) map.get("orderId");
	        String bill_id=(String) map.get("billId");
	        
	        //重置商家的账户余额为0
	        String accountid = AccountCallServiceV2.getAccountId(sellerId);
	        AccountCallServiceV2.resetAccount(accountid, BigDecimal.ZERO, BigDecimal.ZERO);
	               
            Logger.comment("准备前置数据结束");
			writeoffadvanceorderreqBean.setBusinessType(businessType);
			writeoffadvanceorderreqBean.setOrderId(orderId);
			writeoffadvanceorderreqCall.setData(writeoffadvanceorderreqBean);
			writeoffadvanceorderreqCall.callService();		
			

	        
			Logger.verifyEquals("ok", writeoffadvanceorderreqCall.getReturnData(), "验证接口返回ok");		
			Thread.sleep(2000);			
			
			if (writeoffadvanceorderreqCall.getReturnData().equals("ok")){
		        AccountCallServiceV2.resetAccount(accountid, new BigDecimal(99999999), BigDecimal.ZERO);
				verifyDB3(advanced_amount, sellerId,bill_id);				
			}					

		} catch (Exception e) {
			Logger.fail(e);
		}
        //还原商品账户余额
	}
	
}